package com.example.chat.dao;

import com.dragonsoftbravo.jpadsl.JPADslBaseDao;
import com.dragonsoftbravo.jpadsl.PredicateBuilder;
import com.example.chat.model.QUser;
import com.example.chat.model.User;
import com.example.chat.model.ro.UserRo;
import com.example.chat.model.ro.UserSelectRo;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.EntityPathBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;

/**
 * @Description
 * @Date 2022/11/14 10:12
 * @Author pq
 */
@Repository
public class TestDao extends JPADslBaseDao<User,String> {

    @Autowired
    public TestDao(EntityManager entityManager) {
        setEntityManager(entityManager);
    }

    @Override
    public QUser basePath() {
        return QUser.user;
    }
    public List<User> find(UserSelectRo ro){
        PredicateBuilder pb= PredicateBuilder.buildQ();
        pb.like(basePath().account,ro.getSearchValue());
        pb.like(basePath().nickname,ro.getSearchValue());
        pb.like(basePath().avatar,ro.getSearchValue());
        return queryFactory().select(basePath())
                .from(basePath())
                .where(pb.get())
                .fetch();
    };

}
